package com.xzm.project.ui.activity;

import android.view.MenuItem;
import android.view.Window;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import com.xzm.project.util.ToolBarHelper;

/**
 * https://blog.csdn.net/da_caoyuan/article/details/79557704
 */
public class ToolbarHelperActivity extends AppCompatActivity {

//    @Override
//    protected int getLayoutID() {
//        return R.layout.act_toolbar;
//    }
//
//
//
//    private ToolBarHelper mToolBarHelper;
//    public Toolbar toolbar;
//
//    @Override
//    protected void onCreate(Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//
//    }
private ToolBarHelper mToolBarHelper;
    public Toolbar toolbar;
    @Override
    public void setContentView(int layoutResID) {
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        mToolBarHelper = new ToolBarHelper(this, layoutResID);
        toolbar = mToolBarHelper.getToolBar();
        setContentView(mToolBarHelper.getContentView()); /*把 toolbar 设置到Activity 中*/
        setSupportActionBar(toolbar); /*自定义的一些操作*/
        onCreateCustomToolBar(toolbar);
    }
    public void onCreateCustomToolBar(Toolbar toolbar) {
        toolbar.setContentInsetsRelative(0, 0);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

}
